﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Compiler.TableOfSymbols.Types;
using Compiler.Unification.Substitutions;

namespace Compiler.Unification.Constraints
{
    /// <summary>
    /// Ограничение равенства типов
    /// </summary>
    public class SametypeConstraint : BaseTypeConstraint
    {
        public SametypeConstraint(BaseType leftTypeArg, BaseType rightTypeArg)
            : base(leftTypeArg, rightTypeArg)
        { }

        protected override int CategoryWeight
        { 
            get { return 1; } 
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() - 1993*7;
        }

        public override bool IsSameType
        {
            get { return true; }
        }

        public override bool IsSubType
        {
            get { return false; }
        }

        public override BaseTypeConstraint MakeNewConstraint(BaseType leftTypeArg, BaseType rightTypeArg)
        {
            if (leftTypeArg == null)
                throw new ArgumentNullException("leftTypeArg can not be null");
            if (rightTypeArg == null)
                throw new ArgumentNullException("rightTypeArg can not be null");
            return new SametypeConstraint(leftTypeArg, rightTypeArg);
        }

        public override string OperatorString
        {
            get { return " == "; }
        }
    }
}
